const CompressionPlugin = require('compression-webpack-plugin');
module.exports = {
  productionSourceMap: false, // 生产打包时不输出map文件，增加打包速度
  configureWebpack: config => {
    if (process.env.NODE_ENV === 'production') {
      config.optimization.minimizer[0].options.terserOptions.compress.warnings = false
      config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
      config.optimization.minimizer[0].options.terserOptions.compress.drop_debugger = true
      config.optimization.minimizer[0].options.terserOptions.compress.pure_funcs = ['console.log']
    }
    config.plugins.push(new CompressionPlugin({
      algorithm: 'gzip',
      test: /\.(js|css)$/, // 需要压缩的文件类型
      threshold: 10240, // 文件大小超过 10KB 才会被压缩
      minRatio: 0.8, // 压缩比例达到 0.8 才会被压缩
    }),)
  },
  devServer: {
    proxy: {
      '/api': {
        target: 'http://192.168.1.30:9001', // 设置代理目标地址
        changeOrigin: true,
        pathRewrite: {
          '^/api': '' // 将请求路径中的 '/api' 替换为空字符串
        }
      }
    }
  }
};